#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <limits.h>
#include "dominion.h"
#include "rngs.h" 

void testing(struct gameState* game);
void init(struct gameState *game);
void check(char *foo, int bar, int ans);

int main(int argc, char *argv[])
{
	struct gameState *something = malloc(sizeof(struct gameState));

	init(something);

	testing(something);

	free(something);

	return 0;
}

void testing(struct gameState *game)
{
	int fail = 0;
	int cards = 0;
	int treasure = 0;
	int before_h = 0;
	int after_h = 0;
	int expected = 0;
	int player = 0;
	int before_d = 0;
	int after_d = 0;

	for(int i = 0; i < 55; i++)
	{
		int deck = rand() % 70 + 40;
		for(int k = 0; k < deck; k++)
		{
			game->deck[player][i] = (rand() % 75);
		}
		game->deckCount[player] = deck -1;

		int foo = (rand() % deck);
		int bar = (rand() % deck);;
		game->deck[player][foo] = (rand() % 5);
		game->deck[player][bar] = (rand() % 5);

		before_h = game->handCount[player];
		before_d = game->deckCount[player];

		expected = before_d - cards;
		adventurer_card(player, game);
		after_h = game->handCount[player];
		after_d = game->deckCount[player];

		check("before handCount", ((i * 2)), before_h);
		check("after handCount", ((i * 2)), after_h);
		check("before deckCount", (deck - 1), before_d);
		check("after deckCount", ((deck - 1) - cards), after_d);

		printf("number of cards: %d\n", cards);
		printf("deck size: %d\n", deck);

		return;
	}
}

void init(struct gameState *game)
{
	int random = rand() % (INT_MAX -1) +1;
	int *l = malloc(sizeof(int) * 10);
	l = kingdomCards(0,1, 2, 3, 4, 5, 6, 7, 8, 9);
	initializeGame(3, l, random, game);

	return; 
}

void check(char *foo, int bar, int ans)
{
	if(bar == ans)
	{
		printf("%s PASSED, VALUE: %d, EXPECTED: %d\n", foo, ans, bar);
	}
	else
	{
		printf("%s FAILED, VALUE: %d, EXPECTED: %d\n", foo, ans, bar);
	}
}
